home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls074c.sunsparc.Z / tls074c.sunsparc / lib / vtcl / examples / callbacks.tcl < prev    next >
Encoding:
Text File  |  1995-07-20  |  4.5 KB  |  180 lines

  1. #!/bin/vtcl
  2. # ---------------------------------------------------------------------
  3. # Copyright 1994 by SCO, Inc.
  4. # Permission to use, copy, modify, distribute, and sell this software
  5. # and its documentation for any purpose is hereby granted without fee,
  6. # provided that the above copyright notice appear in all copies and that
  7. # both that copyright  notice  and  this  permission  notice  appear  in
  8. # supporting documentation, and that the name  of  SCO  not  be used  in
  9. # advertising or publicity pertaining  to distribution of  the  software
  10. # without   specific,   written  prior   permission.    SCO   makes   no
  11. # representations  about  the  suitability  of  this  software  for  any
  12. # purpose.  It is provided "as is" without express or implied warranty.
  13. # ---------------------------------------------------------------------
  14. #
  15. # Demo        : callbacks.tcl
  16. # Description    : This program simply shows the kind of information,
  17. # Comments    : associated with individual widgets, that is passed 
  18. #        : to a callback function.  
  19. # Highlights    - Use of rowcolumn widget for placing an assortment of
  20. #          widgets on a form.   
  21. #         - Check out the use of "-xmArgs" to affect the foreground
  22. #          color the labels in the callback form.
  23. #
  24.  
  25. proc QuitProgramCB {cbs} {
  26.     # You can put multiple commands on the same line using ';'
  27.     VtClose; exit 0
  28. }
  29.  
  30.  
  31. # This callback displays the information stored in the keyed list 
  32. # that is passed as a parameter ("cbs").  Two rowcolumn widgets are
  33. # placed side-by-side to organize the label widgets in this form.
  34. #
  35. proc GenericCB {widget cbs} {
  36.     VtLock
  37.     global dlog    
  38.     set postDlog [VtFormDialog $dlog.${widget}Dlog \
  39.     -title "$widget Callback Output" \
  40.     -okCallback VxEndFormCB \
  41.     -wmDecoration ALL \
  42.     -allowDuplicateName \
  43.     ]
  44.     set titleLblW [VtLabel $postDlog.titleLblW \
  45.         -label "Command:" \
  46.         -font medNormalFont \
  47.         ]
  48.     set nameLblW [VtLabel $postDlog.nameLblW \
  49.         -label "$widget" \
  50.         -font medItalicFont \
  51.         -leftSide $titleLblW \
  52.         -alignTop $titleLblW \
  53.         ]
  54.     set sepW [VtSeparator $postDlog.sepW \
  55.         -topSide $nameLblW \
  56.         -rightSide FORM \
  57.         -rightOffset 0 \
  58.         -leftOffset 0 \
  59.         ]
  60.     set keyRowC [VtRowColumn $postDlog.keyRowC\
  61.         -topSide $sepW\
  62.         -numColumns 1 \
  63.         -topOffset 0 \
  64.         ]
  65.     set valueRowC [VtRowColumn $postDlog.valueRowC\
  66.         -leftSide  $keyRowC \
  67.         -alignTop  $keyRowC \
  68.         -topOffset 0 \
  69.         -leftOffset 0 \
  70.         -rightSide  FORM \
  71.         -numColumns 1 \
  72.         ]
  73.     set keyLblW [VtLabel $keyRowC.keyLblW \
  74.         -label "Key" \
  75.         -labelCenter \
  76.         -font smallBoldFont \
  77.         ]
  78.     set valueLblW [VtLabel $valueRowC.valueLblW \
  79.         -label "Value" \
  80.         -labelCenter \
  81.         -font smallBoldFont \
  82.         ]
  83.     foreach key [keylkeys cbs] {
  84.         VtLabel $keyRowC.$key -label "$key :" -labelRight \
  85.             -xmArgs "XmNforeground red"
  86.         VtLabel $valueRowC.$key -label [keylget cbs $key]
  87.     }
  88.     VtShow $postDlog
  89.     VtUnLock
  90.     
  91. }
  92.  
  93. # Make connection with the display engine
  94. #
  95. set appShell [VtOpen decor]
  96.  
  97. set dlog [VtFormDialog $appShell.form \
  98.     -title "Demo: Callbacks" \
  99.     -wmDecoration ALL \
  100.     -wmCloseCallback QuitProgramCB \
  101.     ]
  102.  
  103. set labelW [VtLabel $dlog.label \
  104.     -label "Select a widget to see the associated\ncallback information" \
  105.     -font medBoldFont \
  106.     -rightSide FORM \
  107.     ]
  108.  
  109. # here's the rowcolumn manager widget that we'll use to arrange
  110. # the different widgets into two columns.
  111. set rowColumnW [VtRowColumn $dlog.rowcol\
  112.     -topSide $labelW\
  113.     -rightSide  FORM \
  114.     -packing TIGHT \
  115.     ]
  116.  
  117. set pushB [VtPushButton $rowColumnW.pushB \
  118.     -callback "GenericCB VtPushButton" \
  119.     -label "Push Me" \
  120.     -labelCenter \
  121.     ]
  122.  
  123. set rboxW [VtRadioBox $rowColumnW.rboxW \
  124.     -callback "GenericCB VtRadioBox" \
  125.     ]
  126. set tog1W [VtToggleButton $rboxW.red \
  127.     -label "Red" \
  128.     ]
  129. set tog2W [VtToggleButton $rboxW.blue \
  130.     -label "Blue" \
  131.     ]
  132. set tog3W [VtToggleButton $rboxW.green \
  133.     -label "Green" \
  134.     ]
  135.  
  136. set listW [VtList $rowColumnW.listW \
  137.     -callback "GenericCB VtList" \
  138.     -itemList [list ScareCrow TinMan Dorothy Toto] \
  139.     -rows 2 \
  140.     -selection EXTENDED \
  141.     ]
  142.  
  143. set scaleW [VtScale $rowColumnW.scaleW \
  144.     -callback "GenericCB VtScale" \
  145.     -min 0 \
  146.     -max 100 \
  147.     -showValue True \
  148.     -title "Scale Range of Values:" \
  149.     ]
  150.  
  151. set cboxW [VtCheckBox $rowColumnW.cboxW \
  152.     -callback "GenericCB VtCheckBox" \
  153.     ]
  154. set tog1W [VtToggleButton $cboxW.socks \
  155.     -label "socks" \
  156.     ]
  157. set tog2W [VtToggleButton $cboxW.shirts \
  158.     -label "shirts" \
  159.     ]
  160. set tog3W [VtToggleButton $cboxW.shoes \
  161.     -label "shoes" \
  162.     ]
  163.  
  164. set textW [VtText $rowColumnW.textW \
  165.     -callback "GenericCB VtText" \
  166.     -value "Enter something..." \
  167.     -rows 1 \
  168.     ]
  169.  
  170. VtPushButton $dlog.quitPushB \
  171.     -label "Quit" \
  172.     -labelCenter \
  173.     -font medBoldFont \
  174.     -rightSide FORM  \
  175.     -bottomSide FORM  \
  176.     -callback QuitProgramCB
  177.  
  178. VtShow $dlog
  179. VtMainLoop
  180.